package com.cws4cloud.cws.mall.xsm.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cws4cloud.cws.common.core.util.R;
import com.cws4cloud.cws.common.log.annotation.SysLog;
import com.cws4cloud.cws.mall.xsm.entity.Tradelog;
import com.cws4cloud.cws.mall.xsm.service.TradelogService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 订单日志
 *
 * @author zhulj
 * @date 2021-06-19 19:58:53
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/tradelog" )
@Api(value = "tradelog", tags = "订单日志管理")
public class TradelogController {

    private final  TradelogService tradelogService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param tradelog 订单日志
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('mq_tradelog_get')" )
    public R getTradelogPage(Page page, Tradelog tradelog) {
        return R.ok(tradelogService.page(page, Wrappers.query(tradelog)));
    }


    /**
     * 通过id查询订单日志
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('mq_tradelog_get')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(tradelogService.getById(id));
    }

    /**
     * 新增订单日志
     * @param tradelog 订单日志
     * @return R
     */
    @ApiOperation(value = "新增订单日志", notes = "新增订单日志")
    @SysLog("新增订单日志" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('mq_tradelog_add')" )
    public R save(@RequestBody Tradelog tradelog) {
        return R.ok(tradelogService.save(tradelog));
    }

    /**
     * 修改订单日志
     * @param tradelog 订单日志
     * @return R
     */
    @ApiOperation(value = "修改订单日志", notes = "修改订单日志")
    @SysLog("修改订单日志" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('mq_tradelog_edit')" )
    public R updateById(@RequestBody Tradelog tradelog) {
        return R.ok(tradelogService.updateById(tradelog));
    }

    /**
     * 通过id删除订单日志
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除订单日志", notes = "通过id删除订单日志")
    @SysLog("通过id删除订单日志" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('mq_tradelog_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(tradelogService.removeById(id));
    }

}
